package org.bookie.stateful;

import java.util.HashMap;

import org.apache.tapestry.engine.state.StateObjectFactory;

/**
 * Produces application state objects holding conversation state.
 * Conversations are Maps which pass on information about the end of the conversation
 * (i.e. clearance of its state-storage).
 * 
 * @author Marcus Schulte
 */
public class ConversationFactory implements StateObjectFactory {

	private static class Conversation extends HashMap implements StateStorageClearanceListener {
		
		public void clientStateCleared() {
			for ( Object o : values() ) {
				if ( o instanceof StateStorageClearanceListener ) {
					((StateStorageClearanceListener)o).clientStateCleared();
				}
			}
		}
		
	}
	
	
	public Object createStateObject() {
		return new Conversation();
	}

}
